//
//  SettingViewController.m
//  HGMMT
//
//  Created by eport_user1 on 2018/4/16.
//  Copyright © 2018年 eport_user1. All rights reserved.
//

#import "SettingViewController.h"
#import "LinkServers.h"
#import "LinkViewController.h"
#import "LYYNavigationController.h"

@interface SettingViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *titleImageview;

@property (weak, nonatomic) IBOutlet UIButton *logoutButton; //退出按钮
@property (weak, nonatomic) IBOutlet UIButton *registerButton; //注销按钮
@property (weak, nonatomic) IBOutlet UIImageView *showImageView;
@property (weak, nonatomic) IBOutlet UILabel *showLabel;

@end

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self _initView];
   
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)_initView{
    
    
    self.logoutButton.backgroundColor = HGBTN_BackgoundColor;
    [self.logoutButton setTitleColor:HGBTN_TitleColor forState:(UIControlStateNormal)];
    self.logoutButton.titleLabel.font = [UIFont systemFontOfSize:17];
    //self.logoutButton.layer.borderColor = [UIColor blackColor].CGColor;
    //self.logoutButton.layer.borderWidth = 1;
    self.logoutButton.layer.cornerRadius = 5;
    self.logoutButton.layer.masksToBounds = YES;
    
    self.registerButton.backgroundColor = HGBTN_BackgoundColor;
    [self.registerButton setTitleColor:HGBTN_TitleColor forState:(UIControlStateNormal)];
    //self.registerButton.layer.borderColor = [UIColor blackColor].CGColor;
    //self.registerButton.layer.borderWidth = 1;
    self.registerButton.titleLabel.font = [UIFont systemFontOfSize:17];
    self.registerButton.layer.cornerRadius = 5;
    self.registerButton.layer.masksToBounds = YES;
    
    
    self.titleImageview.backgroundColor = [UIColor colorWithRed:236/255.0 green:236/255.0 blue:236/255.0 alpha:1];
    
     NSString *app_Version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    NSString *des = [NSString stringWithFormat:@"HGMMT\nVersion:%@",app_Version];
    self.showLabel.numberOfLines = 0;
    self.showLabel.text = des;
    self.showLabel.textColor = [UIColor colorWithRed:37/255.0 green:80/255.0 blue:155/255.0 alpha:1];
    self.showImageView.image = [UIImage imageNamed:@"FaceShow"];
    
    
}


//退出按钮事件
- (IBAction)logoutAction:(id)sender {
    
    UIAlertController *alterVC = [UIAlertController alertControllerWithTitle:nil message:@"确定要退出么?" preferredStyle:(UIAlertControllerStyleAlert)];
    [alterVC addAction:[UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        [self exitApplication];
        
    }]];
    [alterVC addAction:[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    
    [self presentViewController:alterVC animated:YES completion:nil];
    
}

//注销按钮事件
- (IBAction)regBtnAction:(id)sender {

    
    UIAlertController *alterVC = [UIAlertController alertControllerWithTitle:nil message:@"确定要注销么?" preferredStyle:(UIAlertControllerStyleAlert)];
    [alterVC addAction:[UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
        
        
        
        
        [self disConnectSocket];
    
    }]];
    [alterVC addAction:[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    
    [self presentViewController:alterVC animated:YES completion:nil];
    
    
}

- (void)exitApplication {
    
    //AppDelegate *app = [UIApplication sharedApplication].delegate;
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    
    [UIView animateWithDuration:0.35 animations:^{
        window.alpha = 0;
    } completion:^(BOOL finished) {
        exit(0);
    }];
   
    
}


//断开链接
-(void)disConnectSocket{
    
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    LinkViewController *link = [[LinkViewController alloc]init];
    LYYNavigationController *nav = [[LYYNavigationController alloc]initWithRootViewController:link];
    keyWindow.rootViewController = nav;
    [[LinkServers shareInstance] disConnectSocket];
    
}


@end
